/*     */ package com.hp.bon.logreverse;
/*     */ 
/*     */ import java.io.BufferedReader;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileReader;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStreamReader;
/*     */ import java.util.zip.GZIPInputStream;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class LogFileRead
/*     */   implements ILogFileRead
/*     */ {
/*  16 */   private static final Logger LOG = LoggerFactory.getLogger(LogFileRead.class);
/*  17 */   BufferedReader reader = null;
/*     */   private String fileName;
/*     */   private int lineSeq;
/*     */   private int exceptionNum;
/*     */   private int successNum;
/*     */   private int filteredNum;
/* 126 */   private IDecoder decoder = null;
/* 127 */   private BaseMsgProcess msgProcessor = null;
/*     */ 
/*     */   public String getFileName()
/*     */   {
/*  20 */     return this.fileName;
/*     */   }
/*     */ 
/*     */   public int getLineSeq() {
/*  24 */     return this.lineSeq;
/*     */   }
/*     */ 
/*     */   public int getExceptionNum() {
/*  28 */     return this.exceptionNum;
/*     */   }
/*     */ 
/*     */   public int getSuccessNum() {
/*  32 */     return this.successNum;
/*     */   }
/*     */ 
/*     */   public int getFilteredNum() {
/*  36 */     return this.filteredNum;
/*     */   }
/*     */ 
/*     */   public void readAFile(File file)
/*     */   {
/*  44 */     this.fileName = file.getName();
/*  45 */     this.lineSeq = 0;
/*     */     try {
/*  47 */       this.msgProcessor.beginFileTrigger(this);
/*  48 */       if (file.getName().endsWith(".gz")) {
/*  49 */         GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(file));
/*  50 */         this.reader = new BufferedReader(new InputStreamReader(gzip));
/*     */       } else {
/*  52 */         this.reader = new BufferedReader(new FileReader(file));
/*     */       }
/*  54 */       readByLogEvent();
/*  55 */       this.msgProcessor.endFileTrigger(this);
/*  56 */       this.reader.close();
/*     */     } catch (IOException e) {
/*  58 */       LOG.warn("catch IOException,fileName = " + this.fileName + ",lineSeq=" + this.lineSeq + ":", e);
/*     */ 
/*  60 */       if (this.reader != null)
/*     */         try {
/*  62 */           this.reader.close();
/*     */         }
/*     */         catch (IOException localIOException1)
/*     */         {
/*     */         }
/*     */     }
/*     */     finally
/*     */     {
/*  60 */       if (this.reader != null)
/*     */         try {
/*  62 */           this.reader.close();
/*     */         }
/*     */         catch (IOException localIOException2) {
/*     */         }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void readByLogEvent() {
/*  70 */     this.exceptionNum = 0;
/*  71 */     this.successNum = 0;
/*  72 */     this.filteredNum = 0;
/*     */     try {
/*  74 */       ReverseLogEvent logEvent = null;
/*  75 */       String line = null;
/*  76 */       while ((line = getLine()) != null)
/*     */       {
/*  78 */         if (line.startsWith("201")) {
/*  79 */           if (logEvent != null) {
/*  80 */             processLogEvent(logEvent);
/*     */           }
/*  82 */           logEvent = new ReverseLogEvent(this.lineSeq, this.fileName);
/*  83 */           logEvent.addHeadStr(line);
/*     */         } else {
/*  85 */           logEvent.addMoreStr(line);
/*     */         }
/*     */       }
/*  88 */       if (logEvent != null)
/*  89 */         processLogEvent(logEvent);
/*     */     }
/*     */     catch (IOException e) {
/*  92 */       LOG.warn("catch IOException when read by line,fileName = " + this.fileName + ",lineSeq=" + this.lineSeq + ":", e);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void processLogEvent(ReverseLogEvent logEvent) {
/*     */     try {
/*  98 */       if (this.decoder.isMatch(logEvent))
/*  99 */         if (this.decoder.isParse()) {
/* 100 */           MsgInfo msgInfo = this.decoder.parse();
/* 101 */           if (msgInfo != null) {
/* 102 */             this.msgProcessor.processMsg(msgInfo);
/* 103 */             this.successNum += 1;
/*     */           } else {
/* 105 */             this.exceptionNum += 1;
/*     */           }
/*     */         }
/*     */         else {
/* 109 */           this.filteredNum += 1;
/*     */         }
/*     */     }
/*     */     catch (Exception e) {
/* 113 */       this.exceptionNum += 1;
/* 114 */       LOG.warn("catch Exception,fileName = " + this.fileName + ",lineSeq=" + this.lineSeq + ":", e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void setDecoder(IDecoder decoder) {
/* 119 */     this.decoder = decoder;
/*     */   }
/*     */ 
/*     */   public void setMsgProcessor(BaseMsgProcess msgProcessor) {
/* 123 */     this.msgProcessor = msgProcessor;
/*     */   }
/*     */ 
/*     */   private String getLine()
/*     */     throws IOException
/*     */   {
/* 130 */     this.lineSeq += 1;
/* 131 */     return this.reader.readLine();
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.logreverse.LogFileRead
 * JD-Core Version:    0.6.1
 */